home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 300_01 / contour.doc < prev    next >
Text File  |  1989-12-28  |  8KB  |  159 lines

  1.  
  2.  
  3.                     DOCUMENTATION FOR CONTOUR.C
  4.  
  5.  
  6. PURPOSE:  To produce a plot of contour lines using ASCII characters for 
  7. a series of specified contour levels. Input elevation data is specified 
  8. as a series of grid points at specified grid line spacings.
  9.  
  10. REFERENCE:  BYTE magazine article titled "A Contouring Subroutine" by 
  11. Paul D. Brourke in the June, 1987 issue.  The main subroutine of this 
  12. program is written in BASIC.  It has been converted to C language and 
  13. modified. The reader is referred to the BYTE magazine article for a 
  14. detailed description of the algorithms operation.
  15.  
  16. GENERAL PROGRAM DESCRIPTION: The user prepares an ASCII text file 
  17. contaning the offsets of the x-direction grid lines, the offsets of y-
  18. direction grid lines, the contour lines desired, and the elevation level 
  19. for each x-y grid line intersection. The grid line offsets must be in 
  20. ascending order. Comments may be included in the textfile as long as 
  21. they are enclosed in curly braces. 
  22.  
  23. Here is an example input file named <CONTOUR3.INP>
  24.  
  25.  
  26. 0.0  2.6    6.0   9.0                        {X-Node Values        }
  27. 0.0  1.0    2.0   3.0   4.0   5.0            {Y-Node Values        }
  28. 5.0  8.9                                     {Contour Levels-1..nc }
  29.  
  30. {
  31. Data array - Elevations at grid intersections - A few grid coordinates
  32. are shown to illustrate the grid layout. 
  33. }
  34.  
  35. 3        5        8        9  {9,5}
  36. 4        5        9        10
  37. 5        5        8        11
  38. 4        5        9        10
  39. 3        5{2.6,1} 10       11
  40. 3{0,0}   3        3        4       
  41.  
  42.  
  43. This is the output directed to an ASCII file:
  44.  
  45.  
  46. *----------------------------------------------------------------------*
  47. |                    +                                                 |
  48. |             +++++++                                         ++++++   |
  49. |       ++++++                                           +++++         |
  50. |    +++                                           +++++++             |
  51. | ++++                                      +++++++                    |
  52. | +                                             ++                     |
  53. | +                                               ++                   |
  54. | +                                                 +++                |
  55. | +                                                   +                |
  56. |  +++                                                +                |
  57. |    +++                                            +++                |
  58. |       +                                         ++                   |
  59. |        +++                                  ++++                     |
  60. |           ++                              +++                        |
  61. |             +++                           +                          |
  62. |                ++                       ++                           |
  63. |                  ++                    +                             |
  64. |                    +                   +++++++++++                   |
  65. |                     ++++++++++                    +++++++++++++++++++|
  66. |                               +++                                    |
  67. |                                  ++++++++++++++++++++++++++++++++++++|
  68. |                                                                      |
  69. *----------------------------------------------------------------------*
  70.  
  71.  
  72.  
  73. USER INTERFACE DESCRIPTION:  The program is executed by entering 
  74. "CONTOUR". The user is then prompted for the file name of the input data 
  75. file. The file nane where the data is stored (i.e. INPUT.INP) is then 
  76. entered. The program will execute and plot the specified contours on the 
  77. terminal display. After the plot is complete, the user is queried to 
  78. determine if a copy is desired. If the response is 'yes', the user is 
  79. prompted for an output file name. After the name is provided the 
  80. displayed contour plot is sent to the requested file. If no plot is 
  81. desired the program exits to the operating system.
  82.  
  83. A. INPUT FILE DESCRIPTION: The ASCII file to be read by CONTOUR.EXE can 
  84. be typed up using a separate text editor. The file must be arranged as 
  85. follows:
  86.  
  87.  
  88. Data                                                             
  89. Line No. Data description                                                       
  90. -------  -----------------------------------------------------------
  91.  
  92. 1        A consecutive list of the offsets to each x-direction grid 
  93.          line from the origen separated by spaces or tabs. The origen is 
  94.          the lower left corner of the finished plot and the x-direction 
  95.          grid lines run from the bottom of the plot to the top. Positive 
  96.          offsets are to the right of the origen. The offsets must be in 
  97.          ascending order. 
  98.         
  99.          
  100. 2        A consecutive list of y-grid line offsets. Positive grid 
  101.          offsets are above the origen. The offsets must be in ascending 
  102.          order and separated by spaces or tabs.  
  103.  
  104.  
  105. 3        A consecutive list of contour levels to be plotted. They must 
  106.          be in ascending order and separated be spaces or tabs. The 
  107.          contour levels are interpolated from the grid intersection 
  108.          f(x,y) values provided starting with data line 4.
  109.  
  110.  
  111. 4        Grid intersection f(x,y) value matrix. The lower left value in 
  112.          the matrix is the f(x,y) value for the matrix. The number of 
  113. ..to..   rows in the matrix (#rows) must be equal to the number of values 
  114.          provided in data line 2. The number of columns in the f(x,y) 
  115. #rows    matrix should be equal to the number of values provided in data 
  116.          line 1.
  117.                   
  118. NOTE: Lines containing only comments or which are blank
  119.       are not counted.                                 
  120.  
  121.  
  122. PROGRAM LIMITATIONS:  This program is not universally applicable to all 
  123. situations encountered.  It's primary limitation is related to the 
  124. plotting of contour lines which fall exactly on the established grid 
  125. lines.  If a calculated vector falls on the grid line, no vector is 
  126. generated which leaves a gap in the contour line when plotted.  In the 
  127. real world this does not happen very often and does not present much of 
  128. a problem.  It can be generally be avoided by making sure the contour 
  129. values input at grid points are not entered to coincide with any 
  130. specified contour levels. At any rate the output file can easily be 
  131. dressed up in a text editor if desired. 
  132.  
  133.  
  134. VARIABLE DESCRIPTIONS:
  135.  
  136. iub                    : Grid count in the x-direction
  137. jub                    : Grid count in the y-direction
  138. nc                     : No. of contours to be input
  139. prmerr                 : Error flag for checking input
  140. f(x,x_col,VCT)         : Vector to store x-grid values (MAT_LIB array)
  141. f(y,y_row,VCT)         : Vector to store y-grid values (MAT_LIB array)
  142. f(d,x_col,y_row)       : Array to store grid pt. values(MAT_LIB array)
  143. f(z,contour_no,VCT)    : Vector to store plot contours (MAT_LIB array)
  144. x1                     : Start x-coordinate for pt.
  145. x2                     : Start y-coordinate for pt.
  146. y1                     : End x-coordinate for pt.
  147. y2                     : End y-coordinate for pt.
  148. h [5]                  : Pt. values for a grid square
  149. xh [5]                 : X-coord. for a grid square
  150. yh[5]                  : Y-coord. for a grid square
  151. ish[5]                 : Above/below flags for a grid square
  152. caseval                : Case which controls plot coordinate
  153. m1                     : Pt. 1 for a triangular segment
  154. m2                     : Pt. 2 for a triangular segment
  155. m3                     : Pt. 3 for a triangular segment
  156. dmin                   : Highest f(x,y) value for a grid square
  157. dmax                   : Lowest f(x,y) value for a grid square
  158.  
  159.